package com.example.goandroiddemo.view;

import java.io.File;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

import com.chouren.goandroid.ui.listview.indexable.IndexableListView;
import com.example.goandroiddemo.R;

public class IndexableListViewTestActivity extends Activity {
	private IndexableListView mView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_indexable_listview);
		mView = (IndexableListView)findViewById(R.id.indexable_list_view);
		
		copyDb();
		
		SQLiteDatabase db = new ExpressDbHelper(this).getReadableDatabase();
		Cursor cursor = db.query(ExpressDbHelper.TABLE_COMPANY_NAME, null, null, null, null, null,
				ExpressDbHelper.TABLE_COMPANY_COMPANY_INITIAL);
		mView.setCursor(cursor);
		mView.setClumnName(ExpressDbHelper.TABLE_COMPANY_COMPANY_INITIAL);
		mView.dataSetHasChanged();
	}
	
	private void copyDb(){
		File dbFile = getDatabasePath("express.db");
		CopyFile.copyFileFromResToPhone(dbFile.getParent(),
				dbFile.getName(),
				getResources().openRawResource(R.raw.express));
	}
	
}
